package com.guigu.springcloud.controller;

import com.guigu.springcloud.common.CommonResult;
import com.guigu.springcloud.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@Slf4j
@RequestMapping(value = "/consumer")
public class OrderController {

    public static final String URL = "http://cloud-provider-payment-zoo";

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping(value = "/create")
    public CommonResult<Payment> create(Payment payment) {
        return restTemplate.postForObject(URL + "/payment/create", payment, CommonResult.class);
    }

    @GetMapping(value = "/get/{id}")
    public CommonResult<Payment> getPayment(@PathVariable("id") Long id) {
        return restTemplate.getForObject(URL + "/payment/get/" + id, CommonResult.class);
    }

    @GetMapping(value = "/discovery")
    public CommonResult<Payment> getPaymentDiscovery() {
        return restTemplate.getForObject(URL + "/payment/discovery", CommonResult.class);
    }


    @GetMapping(value = "/zk")
    public CommonResult<Payment> getZkport() {
        return restTemplate.getForObject(URL + "/payment/zk", CommonResult.class);
    }
}
